<?php

class Topcmmchat_Component_Controller_Chatroom extends Phpfox_Component
{
	public function process()
	{
		$oServiceFlashchat = Phpfox::getService('topcmmchat');
        $aSettings = $oServiceFlashchat->getSettings();
        $swfurl = $oServiceFlashchat->getClientUrl();
		$status = $oServiceFlashchat->getStatus();
		$rooms = $oServiceFlashchat->getRooms();
		$users = $oServiceFlashchat->getUsers();
		if ($users != null)
		{
			$users = array_chunk($users, 4, true);
		}

		if ($roomId = $this->request()->get('id'))
		{
			$swfurl .= '&init_room=' . $roomId;
		}
		$title = '123 Flash Chat';
		if (Phpfox::isUser())
		{
			$title .= ', ' . Phpfox::getUserBy('full_name') . '! ';
		}
		else
		{
			$title .= '! ';
		}
		if($aSettings['fc_fullscreen']){
?>
<!DOCTYPE html>
<html>
	<head>
		<meta chatset="UTF-8" />
		<title><?php echo $title;?></title>
	</head>
	<body style="margin:0;overflow:hidden;">
<?php 
	if($aSettings['fc_extendserver']==2){
		$chat .= '<script language="javascript">';
		$chat .= 'var clientWidth = document.body.clientWidth;';
		$chat .= 'var clientHeight = window.innerHeight;';			
		$chat .= 'var htmlcode = \'<script language="javascript" src="'.$swfurl.'&width=\' + clientWidth;';
		$chat .= 'htmlcode += \'&height=\' + clientHeight + \'"></sc\';';
		$chat .= 'htmlcode += \'ript>\';';
		$chat .= 'document.write(htmlcode);';
		$chat .= '</script></body>';		
	}else{
		$chat .=  '<script src="'. $chatSetting['fc_client_loc'] .'123flashchat.js"></script><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,19,0" width="'.$chatSetting['width'].'" height="'.$chatSetting['height'].'" id="topcmm_123flashchat" type="application/x-shockwave-flash">
			<param name=movie value="'.$swfurl.'">
			<param name=quality value="high">
			<param name="menu" value="false">
			<param name="allowScriptAccess" value="always">
			<embed src="'.$swfurl.'" allowScriptAccess="always" quality="high" menu="false" width="'.$chatSetting['width'].'" height="'.$chatSetting['height'].'" type="application/x-shockwave-flash" pluginspace="http://www.macromedia.com/go/getflashplayer"  name="topcmm_123flashchat"></embed>
		</object>
		<script>
			var clientWidth = document.body.clientWidth;
			var clientHeight = window.innerHeight;
			document.getElementsByTagName("body")[0].style.overflow = "hidden";
			document.getElementsByTagName("object")[0].style.width = clientWidth+"px";
			document.getElementsByTagName("embed")[0].style.width = clientWidth+"px";
			document.getElementsByTagName("object")[0].style.height = clientHeight+"px";
			document.getElementsByTagName("embed")[0].style.height = clientHeight+"px";
		</script>'; 		
	}
	echo $chat;
?>
	</body>
</html>
<?php 			
			exit;
		}else{	
			$this->template()->setTitle($title)
						->setBreadcrumb($title)
						->assign(array(
				'status' => $status,
	        	'rooms'  => $rooms,
	        	'users'  => $users,
	        	'swfurl' => $swfurl,
	        	'aSettings' => $aSettings
				)
			);
			$this->template()->assign(array('bUseFullSite' => true));
		}
	}
}

?>